package org.vectrics.user;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.vectrics.common.db.Criteria;
import org.vectrics.company.Company;
import org.vectrics.company.CompanyPersonGroupType;
import org.vectrics.domain.Domain;
import org.vectrics.location.Location;

public class PersonSearchCriteria extends Criteria {

	private static final long serialVersionUID = 8147918683396137740L;

	private String lastName = null;
	private String firstName = null;
	private Set roles = new HashSet();
	private String city = null;
	private String state = null;
	private String anyPhone = null;
	private String email = null;
	private Set personPrivilegeGroupTypes = null;
	private Set companyList = new HashSet();
	private Set groupTypeList = new HashSet();
	private String country = null;
	private boolean showSystemUsers = false;
	private boolean employeesOnly = false; 
	private boolean showParentDomainPeople = false;
	private boolean notEmployees = false;
	private String gender = null;
	private String company = null;
	private String post = null;
	private String university = null;
	private String career = null;
	private String fieldOfStudy = null;
	private String skill = null;

	/**
	 * Conjunto de location con la que se puede buscar a la persona.
	 */
	private Collection<Location> locations = new HashSet();
	
	public PersonSearchCriteria() {
		super();
	}
	
	public boolean getEmployeesOnly() {
		return employeesOnly;
	}

	public void setEmployeesOnly(boolean employeesOnly) {
		this.employeesOnly = employeesOnly;
	}

	/**
	 * @return Returns the companyList.
	 */
	public Set getCompanyList() {
		return companyList;
	}

	/**
	 * @param companyList The companyList to set.
	 */
	public void setCompanyList(Set companyList) {
		this.companyList = companyList;
	}

	public void addCompany(Company company) {
		this.companyList.add(company);
	}
	
	public void addCompanies(Collection<Company> companies) {
		this.companyList.addAll(companies);
	}
	
	/**
	 * @return Returns the showSystemUsers.
	 */
	public boolean getShowSystemUsers() {
		return showSystemUsers;
	}

	/**
	 * @param showSystemUsers The showSystemUsers to set.
	 */
	public void setShowSystemUsers(boolean showSystemUsers) {
		this.showSystemUsers = showSystemUsers;
	}

	/**
	 * @return Returns the groupTypeList.
	 */
	public Set getGroupTypeList() {
		return groupTypeList;
	}

	/**
	 * @param groupTypeList The groupTypeList to set.
	 */
	public void setGroupTypeList(Set groupTypeList) {
		this.groupTypeList = groupTypeList;
	}
	
	public void addGroupType(CompanyPersonGroupType groupType) {
		this.groupTypeList.add(groupType);
	}

	
	/**
	 * @return
	 */
	public String getCity() {
		return city;
	}

	/**
	 * @param city
	 */
	public void setCity(String city) {
		this.city = city;
	}

	/**
	 * @return
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * @param firstName
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * @return
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * @param lastName
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * @return
	 */
	public Set getPrivileges() {
		return roles;
	}

	/**
	 * @param roles
	 */
	public void setPrivileges(Set roles) {
		this.roles = roles;
	}

	public void addPrivilege(String roleCode) {
		this.roles.add(roleCode);
	}

	/**
	 * @return
	 */
	public String getState() {
		return state;
	}

	/**
	 * @param state
	 */
	public void setState(String state) {
		this.state = state;
	}

	public String toString() {
		String roleStr = "[roles:";
		if (getPrivileges() != null) {
			Iterator iter = getPrivileges().iterator();
			while (iter.hasNext()) {
				String role = (String)iter.next();
				roleStr += role + "|";
			}
		}
		roleStr += "]";
		
		String domainStr = "[domains:";
		Iterator iter = this.getDomains().iterator();
		while (iter.hasNext()) {
			Domain domain = (Domain)iter.next();
			domainStr += domain.toString();
		}
		domainStr += "]";
		
		String companyStr = "[companies:";
		iter = this.getCompanyList().iterator();
		while (iter.hasNext()) {
			Company company = (Company)iter.next();
			companyStr += company.toString();
		}
		companyStr += "]";

		return("PersonSelectCriteria[lastName=" + getLastName() + "|firstName=" + getFirstName()
				+ "|email=" + this.email
				+ "|country=" + this.country
				 + "]" + roleStr + domainStr + companyStr);
	}

	/**
	 * @return Returns the anyPhone.
	 */
	public String getAnyPhone() {
		return anyPhone;
	}

	/**
	 * @param anyPhone The anyPhone to set.
	 */
	public void setAnyPhone(String anyPhone) {
		this.anyPhone = anyPhone;
	}

	/**
	 * @return Returns the email.
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email The email to set.
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return Returns the personPrivilegeGroupTypes.
	 */
	public Set getPersonPrivilegeGroupTypes() {
		return personPrivilegeGroupTypes;
	}

	/**
	 * @param personPrivilegeGroupTypes The personPrivilegeGroupTypes to set.
	 */
	public void setPersonPrivilegeGroupTypes(Set personPrivilegeGroupTypes) {
		this.personPrivilegeGroupTypes = personPrivilegeGroupTypes;
	}

	public void addPersonPrivilegeGroup(PersonPrivilegeGroupType groupType) {
		if (this.personPrivilegeGroupTypes == null)
			this.personPrivilegeGroupTypes = new HashSet();
		this.personPrivilegeGroupTypes.add(groupType);
	}

	/**
	 * @return Returns the country.
	 */
	public String getCountry() {
		return country;
	}

	/**
	 * @param country The country to set.
	 */
	public void setCountry(String country) {
		this.country = country;
	}

	public boolean getShowParentDomainPeople() {
		return showParentDomainPeople;
	}

	public void setShowParentDomainPeople(boolean showParentDomainPeople) {
		this.showParentDomainPeople = showParentDomainPeople;
	}

	/**
	 * @return the notEmployees
	 */
	public boolean getNotEmployees() {
		return notEmployees;
	}
	
	/**
	 * @return the notEmployees
	 */
	public boolean isNotEmployees() {
		return notEmployees;
	}

	/**
	 * @param notEmployees the notEmployees to set
	 */
	public void setNotEmployees(boolean notEmployees) {
		this.notEmployees = notEmployees;
	}

	/**
	 * @return the roles
	 */
	public Set getRoles() {
		return roles;
	}

	/**
	 * @param roles the roles to set
	 */
	public void setRoles(Set roles) {
		this.roles = roles;
	}

	/**
	 * @return the gender
	 */
	public String getGender() {
		return gender;
	}

	/**
	 * @param gender the gender to set
	 */
	public void setGender(String gender) {
		this.gender = gender;
	}

	/**
	 * @return the company
	 */
	public String getCompany() {
		return company;
	}

	/**
	 * @param company the company to set
	 */
	public void setCompany(String company) {
		this.company = company;
	}

	/**
	 * @return the post
	 */
	public String getPost() {
		return post;
	}

	/**
	 * @param post the post to set
	 */
	public void setPost(String post) {
		this.post = post;
	}

	/**
	 * @return the university
	 */
	public String getUniversity() {
		return university;
	}

	/**
	 * @param university the university to set
	 */
	public void setUniversity(String university) {
		this.university = university;
	}

	/**
	 * @return the career
	 */
	public String getCareer() {
		return career;
	}

	/**
	 * @param career the career to set
	 */
	public void setCareer(String career) {
		this.career = career;
	}

	/**
	 * @return the fieldOfStudy
	 */
	public String getFieldOfStudy() {
		return fieldOfStudy;
	}

	/**
	 * @param fieldOfStudy the fieldOfStudy to set
	 */
	public void setFieldOfStudy(String fieldOfStudy) {
		this.fieldOfStudy = fieldOfStudy;
	}

	/**
	 * @return the skill
	 */
	public String getSkill() {
		return skill;
	}

	/**
	 * @param skill the skill to set
	 */
	public void setSkill(String skill) {
		this.skill = skill;
	}

	/**
	 * @return the locations
	 */
	public Collection<Location> getLocations() {
		return locations;
	}

	/**
	 * @param locations the locations to set
	 */
	public void setLocations(Collection<Location> locations) {
		this.locations = locations;
	}
	
};
